package com.yanqu.jdbc;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.yanqu.CollectServer;
import com.yanqu.road.utils.MyProperties;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.Map;

public class JdbcTemplateHelper {

    private static JdbcTemplate jdbcTemplate;


    public static void init(){

        MyProperties dbProps = new MyProperties(CollectServer.getConfigPath() + "db_template.properties");

        //初始化jdbc
        jdbcTemplate = new JdbcTemplate(createDruidDataSource(dbProps.getProperties()));

    }

    private static DataSource createDruidDataSource(Map<Object, Object> properties) {
        DataSource center = null;
        try {
            center = DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return center;
    }

    public static JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }
}
